package gr.teiath.newsfeed;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.os.SystemClock;
import android.util.Log;

public class NetworkReceiver extends BroadcastReceiver {

	private static final String tag = NetworkReceiver.class.getSimpleName();
	
	@Override
	public void onReceive(Context context, Intent intent) {
		Log.i(tag,"****** NetworkReceiver // elapsedRealtime(): " + SystemClock.elapsedRealtime());
		
		if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
			
			Intent serviceIntent = new Intent(context, FetchService.class);
			serviceIntent.putExtra(FetchService.INTENT_HANDLE_NETWORK_CHANGE, true);
			context.startService(serviceIntent);
			
			((NewsfeedApplication) context.getApplicationContext()).setAlarmService(false);
		}
	}
}
